<?php

/**
 * Show profile completing percent 
 * @author Tuan
 */
class PercentComplete extends CWidget {

    public function run() {
	/**
	 * except columns is not profile column
	 * percent complete info = 100% - percent of empty column
	 * 
	 */
	//get % complete of profile
	$numOfEmpty = 0;
	foreach (user()->getModel()->attributes as $item) {
	    if ($item == null) {
		$numOfEmpty++;
	    }
	}

	//get % complete of question
	$numOfComplete = 0;
	if (user()->getModel()->more_info) {
	    foreach (user()->getModel()->more_info as $question) {
		if ($question)
		    $numOfComplete++;
	    }
	}


	if ($numOfComplete) {
	    $numOfEmpty = $numOfEmpty - 20;
	} else {
	    $numOfEmpty = $numOfEmpty - 21; //if more_info != null, it will be removed from this accounting
	}

	$percentInfo = number_format(100 - $numOfEmpty * 100 / 18, 2, ',', '');

	$percentQuestion = number_format($numOfComplete * 100 / 9, 2, ',', '');

	$totalPercent = number_format((18 - $numOfEmpty + $numOfComplete) * 100 / 27, 2, ',', '');

	$this->render('percent-complete', array(
	    'percentInfo' => $percentInfo,
	    'percentQuestion' => $percentQuestion,
	    'totalPercent' => $totalPercent
	));
    }

}

